var tmRobin;
var md=new MobileDetect(window.navigator.userAgent);
(function($){
"use strict";
tmRobin=(
function (){
var $window=$(window),
$document=$(document),
$body=$('body');
return {
init: function (){
this.stickyHeader();
this.scrollToTop();
this.blog();
this.switcher();
this.siteMenu();
this.mobileMenu();
this.search();
this.wishlist();
this.miniCart();
this.shop();
this.quickView();
this.notification();
this.compare();
this.ajaxAddToCart();
this.ajaxLoadMore();
this.product();
this.crossSells();
this.swatches();
this.quantityField();
this.imageCarousel();
this.testimonialCarousel();
this.countdown();
this.productCategoriesShortcode();
this.productsShortCode();
this.vcTabs();
this.vcRow();
this.cookie();
this.brand ();
},
stickyHeader: function (){
if(!tmRobinConfigs.sticky_header){
return;
}
var $header=$('.site-header');
if(!$header.length){
return;
}
var $topBar=$('.topbar'),
$logo=$header.find('.site-logo'),
$menu=$header.find('.site-menu'),
$tools=$header.find('.header-tools'),
startOffset=$header.outerHeight();
var stickyHeaderHTML='
';
$header.before(stickyHeaderHTML);
var $stickyHeader=$('.sticky-header');
if($logo.length){
var $img=$stickyHeader.find('.site-logo img');
if($img.length){
var o_logo=$img.attr('data-o_logo');
if(typeof o_logo!=='undefined'){
$img.attr('src', o_logo);
}}
}
if($topBar.length){
startOffset +=$topBar.outerHeight() - 30;
}
if($('#wpadminbar').length){
startOffset +=$('#wpadminbar').outerHeight();
}
$window.scroll(function (){
var currentScroll=$(this).scrollTop(),
$realTools=$('.site-header:not(.sticky-header)').find('.header-tools'),
$stickyTools=$stickyHeader.find('.header-tools');
if(currentScroll > startOffset){
$stickyHeader.addClass('is-sticky');
$header.addClass('real-header');
$realTools.find('>div')
.appendTo('.site-header.sticky-header > .container > .row > .header-tools');
}else{
$stickyTools.find('>div')
.appendTo('.site-header.real-header > .container > .row > .header-tools');
$stickyHeader.removeClass('is-sticky');
$header.removeClass('real-header');
}});
$window.scroll();
},
scrollToTop: function (){
var $scrollToTop=$('.scroll-to-top');
$window.scroll(function (){
if($window.scrollTop() > 100){
$scrollToTop.addClass('show');
}else{
$scrollToTop.removeClass('show');
}});
$scrollToTop.on('click', function(e){
e.preventDefault();
$('body, html').animate({ scrollTop: 0 }, 600);
});
},
fitVideo: function (){
$('.container').fitVids();
},
thumbGallery: function (){
if($('.post-gallery > .slider .single-image').length){
$('.post-gallery > .slider').slick({
slidesToShow:1,
arrows:true,
dots:false,
infinite:true,
adaptiveHeight: true,
});
$('.single-image:not(.slick-cloned)').magnificPopup({
delegate: 'a',
gallery:{
enabled: true,
},
type:'image',
});
}},
blog: function (){
var blogMasonry=function (){
if(typeof(
$.fn.isotope
)==='undefined'||typeof(
$.fn.imagesLoaded
)==='undefined'){
return;
}
var $container=$('.masonry-container');
$container.imagesLoaded(function (){
$container.isotope({
gutter:0,
itemSelector: '.post-teaser--masonry, .masonry-item',
});
});
};
var postsSlider=function (){
$('.js-post-carousel').each(function (){
var $this=$(this),
atts=JSON.parse($this.attr('data-atts'));
if(atts===null){
return;
}
if(typeof atts.auto_play_speed==='undefined'||isNaN(atts.auto_play_speed)){
atts.auto_play_speed=5;
}
var configs={
slidesToShow:parseInt(atts.columns),
slidesToScroll: parseInt(atts.columns),
adaptiveHeight: true,
infinite:atts.loop==='yes',
autoplay:atts.auto_play==='yes',
autoplaySpeed:parseInt(atts.auto_play_speed) * 1000,
prevArrow:'',
nextArrow:'',
responsive:[
{
breakpoint: 992,
settings:{
slidesToShow:3,
slidesToScroll: 3,
},
},
{
breakpoint: 769,
settings:{
slidesToShow:2,
slidesToScroll: 2,
},
},
{
breakpoint: 544,
settings:{
adaptiveHeight: true,
arrows:true,
dots:false,
centerMode:true,
centerPadding:'30px',
slidesToShow:1,
slidesToScroll: 1,
},
},
],
};
if(!atts.nav_type){
configs.arrows=false;
configs.dots=false;
}else{
if(atts.nav_type=='dots'){
configs.arrows=false;
configs.dots=true;
}
if(atts.nav_type=='both'){
configs.arrows=true;
configs.dots=true;
}}
$this.slick(configs);
setTimeout(function (){
var $thumbGallery=$this.find('.post-gallery > .slider');
$thumbGallery.each(function (){
if(typeof $(this).get(0).slick!='undefined'){
$(this).get(0).slick.setPosition();
}});
}, 1000);
});
};
var blogShortcode=function (){
var $posts=$('.tm-robin-blog .posts'),
masonryConfig={
itemSelector:'.post-item',
transitionDuration: 400,
};
if($posts.hasClass('post-carousel-layout')){
return;
}else if($posts.hasClass('post-grid-layout')){
masonryConfig['layoutMode']='fitRows';
}
$posts.isotope(masonryConfig).imagesLoaded(function (){
$posts.isotope('layout');
});
};
tmRobin.fitVideo();
tmRobin.thumbGallery();
blogMasonry();
postsSlider();
blogShortcode();
},
switcher: function (){
var $languageSwitcher=$('.language-switcher select'),
$currencySwitcher=$('.currency-switcher select'),
$WOOCSCurrencySwitcher=$('.currency-switcher.woocs-switcher'),
$WPMLCurrencySwitcher=$('.currency-switcher.wcml-switcher');
var loadCurrency=function(currency){
$.ajax({
type:'post',
url:tmShopieConfigs.ajax_url,
data:{
action:'wcml_switch_currency',
currency: currency,
},
success: function (){
window.location=window.location.href;
},
error:function(error){
console.log(error);
},
});
};
var WOOCSSwitcher=function (){
$('.option', $WOOCSCurrencySwitcher).on('click', function (){
$WPMLCurrencySwitcher.addClass('loading');
var $this=$(this);
$('.currency-switcher').addClass('loading');
setTimeout(function (){
window.location=$this.attr('data-value');
}, 500);
});
};
var wooWPMLSwitcher=function (){
$('.option', $WPMLCurrencySwitcher).on('click', function (){
$WPMLCurrencySwitcher.addClass('loading');
var currency=$(this).find('.option').attr('data-value');
loadCurrency(currency);
});
};
if($('option', $languageSwitcher).length){
$languageSwitcher.niceSelect();
var $niceSelect=$languageSwitcher.next('.nice-select'),
imgSrc=$languageSwitcher.find(':selected').attr('data-imagesrc');
if(typeof imgSrc!='undefined'){
$niceSelect.find('span.current').prepend('');
}
$languageSwitcher.find('option').each(function (){
imgSrc=$(this).attr('data-imagesrc');
var index=$(this).index();
if(typeof imgSrc!=='undefined'){
$niceSelect.find('.option')
.eq(index)
.prepend('');
}});
$body.on('click', '.language-switcher .nice-select .option', function (){
var $this=$(this);
$('.language-switcher').addClass('loading');
setTimeout(function (){
window.location=$this.attr('data-value');
}, 500);
});
}
if($('option', $currencySwitcher).length){
$currencySwitcher.niceSelect();
WOOCSSwitcher();
wooWPMLSwitcher();
}},
siteMenu: function (){
var $siteMenu=$('.site-menu');
if(!$siteMenu.length){
return;
}
var $customMegaMenu=$siteMenu.find('li.mega-menu-custom'),
$normalMegaMenu=$siteMenu.find('li.menu-item:not(.mega-menu)'),
pageContainerRect=$('#page-container')[0].getBoundingClientRect(),
screenWidth=$window.width(),
viewportWidth=$body.hasClass('body-boxed') ? pageContainerRect.right:screenWidth;
var megaMenuOffsets=function (){
if(md.mobile()||md.phone()||md.tablet()){
return;
}
if(!$customMegaMenu.length){
return;
}
$customMegaMenu.on('hover', function (){
setOffset($(this));
}).each(function (){
setOffset($(this));
});
};
var normalMenuHoverBack=function (){
if(md.mobile()||md.phone()||md.tablet()){
return;
}
$normalMegaMenu.on('hover', function (){
hoverBackInit($(this));
}).each(function (){
hoverBackInit($(this));
});
};
var defaultMegaMenu=function (){
if($body.hasClass('error404')){
return;
}
var mainContainerRect=$body.hasClass('single-product') ? $('.site-content > .product > .container')[0].getBoundingClientRect():$('.main-container > .container')[0].getBoundingClientRect(),
leftOffset=$body.hasClass('body-boxed') ? 15:mainContainerRect.left + 15;
if(!md.mobile()&&!md.phone()&&!md.tablet()){
$siteMenu.find('.mega-menu-default').each(function (){
$(this).find('>.sub-menu').css({
'width': mainContainerRect.width - 30,
'left':leftOffset,
});
});
}};
var fullWidthMegaMenu=function (){
if($body.hasClass('error404')){
return;
}
var left=$siteMenu[0].getBoundingClientRect().left,
w=$body.hasClass('body-boxed') ? $('#page-container')[0].getBoundingClientRect().right:$window.width();
$siteMenu.find('.mega-menu-full-width').each(function (){
$(this).find('>.sub-menu').css({
'width': w,
'left':0 - left,
});
});
};
var isOutSide=function($li){
var subMenu=$li.find('>.sub-menu');
if(typeof subMenu[0]=='undefined'){
return;
}
var subMenuRect=subMenu[0].getBoundingClientRect();
return subMenuRect.right >=viewportWidth;
};
var setOffset=function($li){
if(isOutSide($li)){
var $subMenu=$li.find('>.sub-menu'),
subMenuRect=$subMenu[0].getBoundingClientRect(),
sub=subMenuRect.right - pageContainerRect.right;
$subMenu.css({
left: -sub - 15,
});
}};
var hoverBackInit=function($li){
if(isOutSide($li)){
var $subMenu=$('>.sub-menu', $li);
if(!$subMenu.hasClass('hover-back')){
$li.addClass('has-hover-back');
$subMenu.addClass('hover-back');
$('.sub-menu', $subMenu).addClass('hover-back');
}else{
$li.removeClass('has-hover-back');
$subMenu.removeClass('hover-back');
$('.sub-menu', $subMenu).removeClass('hover-back');
}}
};
megaMenuOffsets();
normalMenuHoverBack();
defaultMegaMenu();
fullWidthMegaMenu();
$window.on('resize', function (){
megaMenuOffsets();
normalMenuHoverBack();
defaultMegaMenu();
fullWidthMegaMenu();
});
},
setTopValue: function($el){
var $adminBar=$('#wpadminbar'),
w=$window.width(),
h=$adminBar.height(),
top=h;
if($adminBar.length){
if($adminBar.css('position')=='absolute'&&w <=600){
var t=$adminBar[0].getBoundingClientRect().top;
top=(
t >=0 - h
) ? h + t:0;
}}
if(w >=1200){
return;
}
$el.css('top', top);
},
mobileMenu: function (){
var $mobileBtn=$('.mobile-menu-btn'),
$mobileMenu=$('#site-mobile-menu'),
$mobileMenuClz=$('.site-mobile-menu'),
$pageContainer=$('#page-container');
var caculateRealHeight=function($ul){
var height=0;
$ul.find('>li').each(function (){
height +=$(this).outerHeight();
});
return height;
};
var setUpOverflow=function(h1, h2){
if(h1 < h2){
$mobileMenuClz.css('overflow-y', 'hidden');
}else{
$mobileMenuClz.css('overflow-y', 'auto');
}};
var buildSlideOut=function (){
if(typeof $mobileMenu!=='undefined'&&typeof $pageContainer!=='undefined'){
$body.on('click', '.mobile-menu-btn', function (){
$(this).toggleClass('is-active');
$(this).find('> .hamburger').toggleClass('is-active');
$body.toggleClass('mobile-menu-opened');
tmRobin.setTopValue($mobileMenuClz);
});
$pageContainer.on('click touchstart', function(e){
if(!$(e.target).closest('.mobile-menu-btn').length){
if($body.hasClass('mobile-menu-opened')){
$body.removeClass('mobile-menu-opened');
$mobileBtn.removeClass('is-active');
$mobileBtn.find('> .hamburger').removeClass('is-active');
$mobileMenu.find('#searchform input[type="text"]').blur();
e.preventDefault();
}}
});
setUpOverflow($mobileMenu.height(), $mobileMenuClz.height());
}};
var buildDrillDown=function (){
var level=0,
opener='open',
height=$mobileMenuClz.height();
$mobileMenu.find('li:has(ul)').each(function (){
var $this=$(this),
allLink=$this.find('> a').clone();
if(allLink.length){
$this.prepend(opener);
$this.find('> ul')
.prepend('